package com.example.prison.mapper;

import com.example.prison.entity.AlarmRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【alarm_record】的数据库操作Mapper
* @createDate 2023-05-29 17:22:08
* @Entity com.example.prison.entity.AlarmRecord
*/
@Mapper
public interface AlarmRecordMapper extends BaseMapper<AlarmRecord> {

    @Select("<script>select * from alarm_record " +
            " <where> " +
            " <if test=\"number != null and number != ''\">and number like concat('%',#{number},'%') </if> " +
            " <if test=\"beginTime != null and beginTime != ''\">and time &gt;= #{beginTime} </if> " +
            " <if test=\"endTime != null and endTime != ''\">and time &lt;= #{endTime} </if> " +
            " <if test=\"level != null and level != ''\">and level like concat('%',#{level},'%') </if> " +
            " </where> " +
            "order by id desc</script>")
    List<AlarmRecord> get(@Param("number") String number,@Param("beginTime") String beginTime, @Param("endTime") String endTime,
                          @Param("level") String level);

    @Insert("insert into alarm_record(number, time, level, solve, duty_people, process_people, process_time, device, mark_id,statusA,statusB,statusC) " +
            "values (#{number}, #{time}, #{level}, #{solve}, #{dutyPeople}, #{processPeople}, #{processTime}, #{device}, " +
            "#{MarkId},#{statusA},#{statusB},#{statusC})")
    int add(AlarmRecord record);

    @Delete("<script>delete from alarm_record where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleteRecord(@Param("ids") Integer[] ids);

    @Update("update alarm_record set solve='已处理', duty_people=#{dutyPeople}, process_people=#{processPeople}, process_time=#{processTime} where id = #{id}")
    int updateRecord(Integer id, String dutyPeople, String processPeople, String processTime);

    @Update("update alarm_record set solve='已推送', process_people=#{processPeople} where id = #{id}")
    int updatePushRecord(Integer id, String processPeople);

    @Select("select * from alarm_record where id = #{id}")
    AlarmRecord getById(@Param("id") Integer id);


    @Select("select * from alarm_record where number=#{number} and level=#{level} order by id desc")
    List<AlarmRecord> getOneByNumberAndLevel(@Param("number") String number,@Param("level") String level);


}




